package com.cdu.guoxinan.www.smartcom.controller;

import com.cdu.guoxinan.www.smartcom.domian.vo.LogStatsVO;
import com.cdu.guoxinan.www.smartcom.service.UserLogService;
import com.cdu.guoxinan.www.smartcom.unit.model.R;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.*;

@RestController
@RequestMapping("/syslog")
public class UserLogController {
    @Resource
    private UserLogService userLogService;

    @GetMapping("/stats")
    public LogStatsVO  getStats() {
        return userLogService.getLogStats();
    }

    @GetMapping("/hourly")
    public R getHourly() {
        Date end = new Date();
        Date start = new Date(end.getTime() - 24 * 60 * 60 * 1000);
        return userLogService.getLogCountByHour(start, end);
    }

    @GetMapping("/table")
    public R getTable(Integer page, Integer limit) {
        Date end = new Date();
        Date start = new Date(end.getTime() - 3L * 24 * 60 * 60 * 1000);
        return userLogService.getRecentLogTable(start, end, page, limit);
    }
}